#include <stdio.h>
// 计算 switch实现 ,使用回调函数
int add(int x, int y)
{
    return x + y;
}
int sub(int x, int y)
{
    return x - y;
}
int mul(int x, int y)
{
    return x * y;
}
int div(int x, int y)
{
    return x / y;
}
void menu(){
    printf("******************\n");
    printf("**1.add    2.sub**\n");
    printf("**3.mul    4.div**\n");
    printf("**     0.exit   **\n");
    printf("******************\n");
}
// pf 回调函数
// 
void calc(int (*pf)(int, int), x,y){
    pf(x,y);
}
int main()
{
    menu();
    int num, x, y = 0;
    do{
        printf("please input num \n");
        scanf("%d", &num);
        printf("please input two numbers \n");
        scanf("%d %d", &x, &y);
        switch (num)
        {
        case 1:
            calc(add,x,y);
            break;
        case 2:
            calc(sub, x, y);
            break;
        case 3:
            calc(mul, x, y);
            break;
        case 4:
            calc(div, x, y);
            break;
        default:
            break;
        }
    }while(num);
    
    return 0;
}
